home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / strlib.zip / STRPACK.C < prev    next >
Text File  |  1993-01-04  |  1KB  |  41 lines

  1.  
  2. /*  File   : strpack.c
  3.     Author : Richard A. O'Keefe.
  4.     Updated: 20 April 1984
  5.     Defines: strpack()
  6.  
  7.     strpack(dst, src, set, c)
  8.     copies characters from src to dst, stopping when it finds a NUL.  If
  9.     c is NUL, characters in set are not copied to dst.  If c is not NUL,
  10.     sequences of characters from set are copied as a single c.
  11.     strpack(d, s, " \t", ' ') can be used to compress white space,
  12.     strpack(d, s, " \t", NUL) to eliminate it.  To translate  characters
  13.     in  set to c without compressing runs, see strtrans(). The result is
  14.     the address of the NUL byte now terminating dst.  Note that dst  may
  15.     safely be the same as src.
  16. */
  17.  
  18. #include "strings.h"
  19. #include "_str2set.h"
  20.  
  21. char *strpack(dst, src, set, c)
  22.     register _char_ *dst, *src;
  23.     char *set;
  24.     register int c;
  25.     {
  26.         register int chr;
  27.  
  28.         _str2set(set);
  29.         while (chr = *src++) {
  30.             if (_set_vec[chr] == _set_ctr) {
  31.                 while ((chr = *src++) && _set_vec[chr] == _set_ctr) ;
  32.                 if (c) *dst++ = c;      /* 1. If you don't want trailing */
  33.                 if (!chr) break;        /* 2. things turned into "c", swap */
  34.             }                           /* lines 1 and 2. */
  35.             *dst++ = chr;
  36.         }
  37.         *dst = 0;
  38.         return dst;
  39.     }
  40.  
  41.